//
//  ViewController.m
//  Attention
//
//  Created by student on 16/2/18.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"

// 练习:
// 1. 分析整个应用中当前有多少对象?罗列出来
//  UIAlertView(3个)
//  UIActionSheet(1个)
//  UIWindow(1个)
//  UIView
//  UILabel
//  UI

// 2. 使用Reveal查看程序结构
// 3. 使用纯代码实现本程序

@interface ViewController ()<UIAlertViewDelegate,UIActionSheetDelegate>
@property (weak, nonatomic) IBOutlet UILabel *infoLabel;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)btn1Pressed:(id)sender
{
    UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:@"弹出框标题" message:@"弹出框信息" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
    [alertview show];
    
}

- (IBAction)btn2Pressed:(id)sender
{
    UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:@"弹出窗口2" message:@"吃了吗" delegate:self cancelButtonTitle:@"吃了" otherButtonTitles:@"正在吃",@"还没吃", nil];
    [alertview show];
    
}

- (IBAction)btn3Pressed:(id)sender
{
    UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:@"登入" message:@"请输入用户名和密码" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消",nil];
    alertview.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
    [alertview show];
    
}


#pragma mark - 弹出操作表(UIActionSheet)

- (IBAction)btn4Pressed:(id)sender
{
  UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"小明一起吃饭吗"
                                                     delegate:self
                                            cancelButtonTitle:@"我吃过了,你去吧."
                                       destructiveButtonTitle:@"好的,一起去"
                                            otherButtonTitles:@"一起吃吃KFC",@"一起去吃MC", nil];
    [sheet showInView:self.view];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSLog(@"用户点了第%i个按钮，按钮的文字信息是：%@",buttonIndex+1,[alertView buttonTitleAtIndex:buttonIndex]);
    NSLog(@"弹窗的信息:%@",alertView.title);
    if ([alertView.title isEqualToString:@"登入"])
    {
        NSString *info = [NSString stringWithFormat:@"用户名：%@ m密码：%@",[alertView textFieldAtIndex:0].text,[alertView textFieldAtIndex:1].text];
        self.infoLabel.text = info;
    }
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSLog(@"操作表的标题：%@",actionSheet.title);
    NSLog(@"用户选择了哪一个按钮:%i,%@",buttonIndex,[actionSheet buttonTitleAtIndex:buttonIndex]);
    if(buttonIndex == actionSheet.destructiveButtonIndex)
    {
        NSLog(@"用户点了destructiveBtn");
    }
    else if(buttonIndex == actionSheet.cancelButtonIndex)
    {
        NSLog(@"用户点了cancelBtn");
    }

}



@end
